package telas;

import classes.Clientes;
import classes.Cpf;
import classes.Dados;
import java.awt.Component;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class CadastroDeClientes extends javax.swing.JDialog {
    
    private static final int VISUALIZACAO = 1;//não pode 
    private static final int EDICAO = 2;
    private static final int INSERCAO = 3;
    private Clientes cliente;
    private Dados dados;
    private int estado;
    private int cont = 0;
    private int corrente = -1;

   

    public CadastroDeClientes(java.awt.Frame parent, boolean modal, Clientes cliente) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        this.cliente = cliente;
        
        jLcpf.setVisible(false);
        dados = cliente.getCliente(cliente.getContContatos());
        setEstado(VISUALIZACAO);
        load();
        exibeDados();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPDados = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTCpf = new javax.swing.JFormattedTextField();
        jTTelefone = new javax.swing.JFormattedTextField();
        jTNome = new javax.swing.JTextField();
        jLcpf = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jbNovo = new javax.swing.JButton();
        jbEditar = new javax.swing.JButton();
        jbLimpar = new javax.swing.JButton();
        jbExcluir = new javax.swing.JButton();
        jbSalvar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jbPrimeiro = new javax.swing.JButton();
        jbAnterior = new javax.swing.JButton();
        jbProximo = new javax.swing.JButton();
        jbUltimo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Eclipse Lan House");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Nome:");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("CPF:");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Telefone:");

        try {
            jTCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jTCpf.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTCpfKeyReleased(evt);
            }
        });

        jLcpf.setFont(new java.awt.Font("Vani", 0, 18)); // NOI18N
        jLcpf.setForeground(new java.awt.Color(255, 0, 0));
        jLcpf.setText("Inválido");
        jLcpf.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        javax.swing.GroupLayout jPDadosLayout = new javax.swing.GroupLayout(jPDados);
        jPDados.setLayout(jPDadosLayout);
        jPDadosLayout.setHorizontalGroup(
            jPDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPDadosLayout.createSequentialGroup()
                .addGroup(jPDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPDadosLayout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPDadosLayout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(17, 17, 17)
                        .addComponent(jLcpf))
                    .addGroup(jPDadosLayout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        jPDadosLayout.setVerticalGroup(
            jPDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPDadosLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(10, 10, 10)
                .addGroup(jPDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2))
                    .addComponent(jLcpf, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jPDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)))
        );

        jbNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/New16.gif"))); // NOI18N
        jbNovo.setText("Novo");
        jbNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNovoActionPerformed(evt);
            }
        });

        jbEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/gtk-edit.png"))); // NOI18N
        jbEditar.setText("Editar");
        jbEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEditarActionPerformed(evt);
            }
        });

        jbLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/limpar.GIF"))); // NOI18N
        jbLimpar.setText("Limpar");
        jbLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbLimparActionPerformed(evt);
            }
        });

        jbExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Delete16.gif"))); // NOI18N
        jbExcluir.setText("Excluir");
        jbExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbExcluirActionPerformed(evt);
            }
        });

        jbSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Save16.gif"))); // NOI18N
        jbSalvar.setText("Salvar");
        jbSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSalvarActionPerformed(evt);
            }
        });

        jbPrimeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/first.png"))); // NOI18N
        jbPrimeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbPrimeiroActionPerformed(evt);
            }
        });

        jbAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/previous.png"))); // NOI18N
        jbAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAnteriorActionPerformed(evt);
            }
        });

        jbProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/next.png"))); // NOI18N
        jbProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbProximoActionPerformed(evt);
            }
        });

        jbUltimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/last.png"))); // NOI18N
        jbUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbUltimoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(145, 145, 145)
                .addComponent(jbPrimeiro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbAnterior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbProximo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbUltimo)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbPrimeiro)
                    .addComponent(jbAnterior)
                    .addComponent(jbProximo)
                    .addComponent(jbUltimo))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbLimpar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(106, 106, 106))
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbNovo)
                    .addComponent(jbEditar)
                    .addComponent(jbLimpar)
                    .addComponent(jbExcluir)
                    .addComponent(jbSalvar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jPDados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPDados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalvarActionPerformed
        String cpf = jTCpf.getText().replaceAll("\\.", "");
        cpf = cpf.replaceAll("-", "");
        
        if (jTNome.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Preencha o Campo Nome!", "Aviso", JOptionPane.INFORMATION_MESSAGE);
        } else if (cpf.trim().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Preencha o Campo Cpf corretamente!", "Aviso", JOptionPane.INFORMATION_MESSAGE);
        } else if (jTTelefone.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Preencha o Campo Numero!", "Aviso", JOptionPane.INFORMATION_MESSAGE);
        } else {
            Dados dadoCliente = new Dados(jTNome.getText(), jTCpf.getText(), jTTelefone.getText());
           
            if(estado == 3){//cadastrar
                String[][] con = cliente.getUsuarios();
                for(int i = 0; i < con.length; i++){
                    if(jTCpf.getText().equalsIgnoreCase(con[i][1])){
                        JOptionPane.showMessageDialog(this, "CPF ja existe!!", "Aviso", JOptionPane.INFORMATION_MESSAGE);
                        jTCpf.setFocusable(true);
                        return;
                    }        
                }
                if (cliente.cadastraCliente(dadoCliente)) {
                     
                    JOptionPane.showMessageDialog(this, "Cadastrado com Sucesso","Aviso",JOptionPane.INFORMATION_MESSAGE);
                    cont++;

                } else {
                    JOptionPane.showMessageDialog(this, "Erro ao cadastrar","Aviso",JOptionPane.ERROR_MESSAGE);
                    setEstado(VISUALIZACAO);
                    return;
                }
            }else{//editar
                
                if(cliente.editarCliente(dadoCliente)){
                    JOptionPane.showMessageDialog(this, "Editado com Sucesso","Aviso",JOptionPane.INFORMATION_MESSAGE);
                }else{
                    JOptionPane.showMessageDialog(this, "Erro ao Editar","Aviso",JOptionPane.ERROR_MESSAGE);
                    setEstado(VISUALIZACAO);
                    return;
                }
            }
             
        }
        corrente = cliente.getContContatos() - 1;
        setEstado(VISUALIZACAO);
        exibeDados();
        
    }//GEN-LAST:event_jbSalvarActionPerformed

    private void jbNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNovoActionPerformed
        setEstado(INSERCAO);
    }//GEN-LAST:event_jbNovoActionPerformed

    private void jTCpfKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTCpfKeyReleased
         if (jTCpf.getText().trim().toCharArray().length == 14) {
            Cpf cpf = new Cpf();
            if (!cpf.verificaCpf(jTCpf.getText())) {
                jLcpf.setVisible(true);
            } else {
                jLcpf.setVisible(false);
            }
        } else {
            evt.consume();
        }
    }//GEN-LAST:event_jTCpfKeyReleased

    private void jbExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbExcluirActionPerformed
        if(corrente > -1){
            
            if(cliente.removeCliente(jTCpf.getText())){
                JOptionPane.showMessageDialog(this, "Dados excluidos com Sucesso!","Aviso",JOptionPane.INFORMATION_MESSAGE);
                corrente--;
                cont = cliente.getContContatos();
                exibeDados();
            }else{
                JOptionPane.showMessageDialog(this, "Não foi possivel excluir!","Aviso",JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }//GEN-LAST:event_jbExcluirActionPerformed

    private void jbAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAnteriorActionPerformed
       if(corrente == -1){
            JOptionPane.showMessageDialog(this, "Não ha dados cadastrados!");
        }else{
            if(corrente >= 1){
                corrente--;
                exibeDados();
            }else{
                JOptionPane.showMessageDialog(this, "Já é o primeiro registro!");
            }
        }
    }//GEN-LAST:event_jbAnteriorActionPerformed

    private void jbProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbProximoActionPerformed
        if(corrente == -1){
            JOptionPane.showMessageDialog(this, "Não ha dados cadastrados!");
        }else{
            if(corrente < cont-1){
                corrente++;
                exibeDados();
            }else{
                JOptionPane.showMessageDialog(this, "Já é o ultimo registro!");
            }
        }
    }//GEN-LAST:event_jbProximoActionPerformed

    private void jbPrimeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbPrimeiroActionPerformed
        corrente = cliente.first();
        exibeDados();
    }//GEN-LAST:event_jbPrimeiroActionPerformed

    private void jbUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbUltimoActionPerformed
        corrente = cliente.last();
        exibeDados();
    }//GEN-LAST:event_jbUltimoActionPerformed

    private void jbLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbLimparActionPerformed
        limpaCampos(jPDados);
        jTNome.requestFocus();
    }//GEN-LAST:event_jbLimparActionPerformed

    private void jbEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEditarActionPerformed
           setEstado(EDICAO);
    }//GEN-LAST:event_jbEditarActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        load();
        setEstado(1);
        exibeDados();
    }//GEN-LAST:event_formWindowOpened

    private void setEstado(int estado) {
        this.estado = estado;
        if (estado == 1) {//visualização
            jTNome.setEditable(false);
            jTTelefone.setEditable(false);
            jTCpf.setEditable(false);
            jbAnterior.setEnabled(cont != 0);
            jbPrimeiro.setEnabled(cont != 0);
            jbProximo.setEnabled(cont != 0);
            jbUltimo.setEnabled(cont != 0);
            jbNovo.setEnabled(true);
            jbEditar.setEnabled(cont != 0);
            jbSalvar.setEnabled(false);
            jbExcluir.setEnabled(cont != 0);
            jbLimpar.setEnabled(false);
        } else if (estado == 2) {//edição
            jTNome.setEditable(true);
            jTTelefone.setEditable(true);
            jTCpf.setEditable(false);
            jbAnterior.setEnabled(false);
            jbPrimeiro.setEnabled(false);
            jbProximo.setEnabled(false);
            jbUltimo.setEnabled(false);
            jbNovo.setEnabled(false);
            jbEditar.setEnabled(false);
            jbSalvar.setEnabled(true);
            jbExcluir.setEnabled(false);
            jbLimpar.setEnabled(true);
            jTNome.requestFocus();
        } else {
            if (estado == 3) {//inserção
                jTNome.setEditable(true);
                jTTelefone.setEditable(true);
                jTCpf.setEditable(true);
                jbAnterior.setEnabled(false);
                jbPrimeiro.setEnabled(false);
                jbProximo.setEnabled(false);
                jbUltimo.setEnabled(false);
                jbNovo.setEnabled(false);
                jbEditar.setEnabled(false);
                jbSalvar.setEnabled(true);
                jbExcluir.setEnabled(false);
                jbLimpar.setEnabled(true);
                limpaCampos(jPDados);
                jTNome.requestFocus();
            }
        }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLcpf;
    private javax.swing.JPanel jPDados;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JFormattedTextField jTCpf;
    private javax.swing.JTextField jTNome;
    private javax.swing.JFormattedTextField jTTelefone;
    private javax.swing.JButton jbAnterior;
    private javax.swing.JButton jbEditar;
    private javax.swing.JButton jbExcluir;
    private javax.swing.JButton jbLimpar;
    private javax.swing.JButton jbNovo;
    private javax.swing.JButton jbPrimeiro;
    private javax.swing.JButton jbProximo;
    private javax.swing.JButton jbSalvar;
    private javax.swing.JButton jbUltimo;
    // End of variables declaration//GEN-END:variables

    private void load(){
        corrente = cliente.getContContatos() - 1;
        cont = cliente.getContContatos();
    }
    
    private void exibeDados(){
        if(corrente != -1){
            limpaCampos(jPDados);
            dados = cliente.getCliente(corrente);
            jTNome.setText(dados.getNome());
            jTCpf.setText(dados.getCpf());
            jTTelefone.setText(dados.getTelefone());
        }else{
            limpaCampos(jPDados);
        }
    }
    
    private void limpaCampos(JPanel painel){
        Component[] componentes = painel.getComponents();
        JTextField campo;
        
        for(int i = 0; i < componentes.length; i++){
            if(componentes[i] instanceof javax.swing.JTextField){
                campo = (javax.swing.JTextField)componentes[i];
                campo.setText("");
            }
        }
    }
    
    
}
